<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:c="livcos.org/ns/cosmos"
  xmlns:f="livcos.org/ns/xslt/function"
  exclude-result-prefixes="c f">
  
	<xsl:import href="../../../web/admin/snapshot/base.xsl"/>
	<xsl:import href="../../../web/style/config.xsl"/>
  
  <xsl:variable name="projObjId" select="'/livcos.org/LivCos'"/>

	<xsl:variable name="dataObj" select="document(concat($projObjId, '/data.meta'))/*"/>
  
  <xsl:template match="/">
    <snapshot>
      
      <source root="{$projObjId}/web"/>
      <target url="{$config/static-web/root/@url}"/>

      <xsl:apply-templates select="$dataObj/c:community/c:*" mode="doc"/>
      <xsl:apply-templates select="$dataObj/c:article/c:*" mode="doc"/>
      <xsl:apply-templates select="$dataObj/c:concept/c:*" mode="doc"/>
    	<xsl:apply-templates select="$dataObj/c:pm/c:Roadmap" mode="doc"/>
    	<xsl:apply-templates select="$dataObj/c:pm/c:Roadmap07" mode="doc"/>
    	<xsl:apply-templates select="$dataObj/c:pm/c:HelpWanted" mode="doc"/>
    	<xsl:apply-templates select="$dataObj/c:pm/c:releases/c:*" mode="doc"/>
    	<xsl:apply-templates select="$dataObj/c:manual/c:Install" mode="doc"/>
    	<xsl:apply-templates select="$dataObj/c:project/c:Web/c:Manual" mode="doc"/>
    	<xsl:apply-templates select="$dataObj/c:project/c:Web/c:image" mode="doc"/>
    	<xsl:apply-templates select="$dataObj/c:image" mode="doc"/>
      <xsl:apply-templates select="$dataObj/c:media" mode="doc"/>
      <resource ref="../../LivCos/web/css/main.css" out="./css/main.css"/>
      <resource ref="../../LivCos/web/css/intro.css" out="./css/intro.css"/>
      <resource ref="../../LivCos/web/css/journal.css" out="./css/journal.css"/>
      <resource ref="../../web/css/styles.css" out="./css/styles.css"/>
      <resource ref="../../web/img/pdf.gif" out="./image/pdf.gif"/>
      <resource ref="../../web/img/doc.png" out="./image/doc.png"/>
      <resource ref="../../web/img/rtf.gif" out="./image/rtf.gif"/>
    	<resource ref="PublicIntro.view" out="index.html"/>
    	
    	<resource ref="../../Map/web/Intro.html" out="Map/Intro.html"/>
    	<resource ref="../../Map/web/UserGuide.html" out="Map/UserGuide.html"/>
    	<xsl:apply-templates select="doc('/livcos.org/Map/data/image.meta')/*/*" mode="single">
    		<xsl:with-param name="prefix" select="'Map/image/'"/>
    	</xsl:apply-templates>
    	<resource ref="/livcos.org/web/css/styles.css" out="Map/css/styles.css"/>
    	
    	<replace pattern=".*nav\.html\?" value="http://livcos.org:8080/livcos.org/Map/web/nav.html?"/>
    	<replace pattern=".*/demo\.livcos\.org/" value="http://livcos.org:8080/demo.livcos.org/"/>
    	<replace pattern="\.\./\.\./\.\./LivCos/web/" value="../"/>
    	<replace pattern="\.\./\.\./LivCos/web/" value="../"/>
    	
    </snapshot>
  </xsl:template>
  
	<xsl:template match="c:*" mode="single">
		<xsl:param name="prefix"/>
		<xsl:variable name="ext" select="f:file-ext(.)"/>
		<resource ref="{f:object-id(.)}.{$ext}" out="{$prefix}{f:object-name(.)}.{$ext}"/>
	</xsl:template>
	
	<xsl:template match="c:*" mode="doc">
		<xsl:variable name="uri" select="substring-after(f:object-relative-name(.), 'data/')"/>
		<resource ref="{$uri}.html"/>
		<resource ref="{$uri}.pdf"/>
	</xsl:template>
	
	<xsl:template match="c:*[c:*]" mode="doc">
    <xsl:apply-templates select="c:*" mode="doc"/>
  </xsl:template>
  
  <xsl:template match="c:image[c:*] | c:media[c:*]" mode="doc" priority="1">
    <xsl:apply-templates select="c:*" mode="content">
    	<xsl:with-param name="prefix" select="concat($projObjId, '/data')"/>
    </xsl:apply-templates>
  </xsl:template>
  
  <xsl:template match="c:Roadmap" mode="doc">
    <xsl:variable name="pathNodes" select="ancestor-or-self::*[position() &lt; last()]"/>
    <xsl:variable name="uri"
      select="string-join(for $n in $pathNodes return local-name($n), '/')"/>
    <resource ref="{$uri}.html" out="{$uri}.html"/>
    <resource ref="{$uri}.pdf" out="{$uri}.pdf"/>
  </xsl:template>
  
</xsl:stylesheet>
